package com.yanqu.backendweb.controller;

import com.alibaba.fastjson.JSON;
import com.yanqu.backendweb.service.impl.UnionInfoServiceImpl;
import com.yanqu.backendweb.utils.Response;
import com.yanqu.backendweb.utils.Utils;
import com.yanqu.backendweb.vo.RoleDetailVo;
import com.yanqu.backendweb.vo.UnionDetailVo;
import com.yanqu.backendweb.vo.UnionInfoVo;
import com.yanqu.backendweb.vo.UnionRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.SortedMap;

/**
 * @author duli
 * @version 1.0
 * @date 2020/10/16 17:09
 * @Description 商会
 */
@Controller
@RequestMapping("/union")
public class UnionInfoController {
    @Autowired
    private UnionInfoServiceImpl unionInfoService;
    /*
     * 获取商会列表
     * */
    @RequestMapping("/get")
    @ResponseBody
    public Response get(String requestId, String sign, @RequestBody @Valid UnionInfoVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag=Utils.checkSign(paramMap,sign);
        if(flag){
            return unionInfoService.get(vo);
        }else{
            return Response.singError();
        }
    }
    /*
     * 获取商会详情
     * */
    @RequestMapping("/getDetail")
    @ResponseBody
    public Response getDetail(String requestId, String sign, @RequestBody @Valid UnionDetailVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag=Utils.checkSign(paramMap,sign);
        if(flag){
            return unionInfoService.getDetail(vo);
        }else{
            return Response.singError();
        }

    }
    /*
     * 获取商会成员列表
     * */
    @RequestMapping("/getMember")
    @ResponseBody
    public Response getMember(String requestId, String sign, @RequestBody @Valid UnionRoleVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag=Utils.checkSign(paramMap,sign);
        if(flag){
            return unionInfoService.getMember(vo);
        }else{
            return Response.singError();
        }
    }
    /*
     * 获取玩家商会详情
     * */
    @RequestMapping("/getRoleDetail")
    @ResponseBody
    public Response getRoleDetail(String requestId, String sign, @RequestBody @Valid RoleDetailVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag=Utils.checkSign(paramMap,sign);
        if(flag){
            return unionInfoService.getRoleDetail(vo);
        }else{
            return Response.singError();
        }
    }
}
